package month4.day13;

import org.omg.CORBA.PUBLIC_MEMBER;

public class PC {
    private String brand;
    private String color;
    private String size;
    private int hardDiskcapacity;//硬盘容量
    Dish []dishes=new Dish[0];

    //判断软件重名
    public boolean chongming(int fp,String name){
        for(int i=0;i<fp;i++){
            for(int j=0;j<dishes[i].soft;j++){
                if(dishes[i].softwares[j].getName().equals(name))
                    return true;
            }
        }
        return false;
    }
//给硬盘分盘
    public void fenpan(int fp,String s1[],int i1[]){
        Dish []dishes1=new Dish[fp];
        for(int i=0;i<fp;i++){
            Dish di=new Dish(s1[i],i1[i]);
            dishes1[i]=di;
        }
        dishes=dishes1;
    }
//安装系统
    public OS os(String azp){
        int i = 0;
        for (; i < dishes.length; i++) {
            if (dishes[i].getName().equals(azp)) {
                if (dishes[i].getRemaining() >= 7000) {
                    System.out.println("安装成功，大小为7000M");
                    OS os=new OS(azp,7000);
                    dishes[i].setRemaining(dishes[i].getRemaining() - 7000);
                    return os;
                } else {
                    System.out.println("所选磁盘容量不足，请重新选择");
                    return null;
                }
            }
        }
        if (i == dishes.length)
            System.out.println("没有这个盘，请重新输入");
        return null;
    }
    //安装软件
    public Software software(int ruanjian,String name,double capacity,String dish){
        for (int i = 0; i < dishes.length; i++) {
            if (dishes[i].getName().equals(dish)) {
                if (dishes[i].getRemaining() >= capacity) {
                    Software software;
                    if (ruanjian == 1) {
                         software=new Software(name,capacity,dish);
                    } else {
                         software=new DownloadSoftware(name,capacity,dish);
                    }
                    dishes[i].anzhuang(software);
                    dishes[i].soft++;
                    System.out.println("安装成功，大小为"+capacity+"M");
                    dishes[i].setRemaining(dishes[i].getRemaining() - capacity);
                    return software;
                } else {
                    System.out.println("所选磁盘容量不足，请重新选择");
                    return null;
                }
            }
        }
        System.out.println("安装失败，所选磁盘不存在");
        return null;
    }
    //启动软件
    public Software software(String name){
        for(int i=0;i<dishes.length;i++){
            for(int j=0;j<dishes[i].soft;j++){
                if(dishes[i].softwares[j].getName().equals(name)){
                    if(dishes[i].softwares[j] instanceof Download){
                        return dishes[i].softwares[j];
                    }
                }
            }
        }
        return null;
    }
    //展示选择磁盘中的软件
    public void ruanjian(String dish){
        for (int i = 0; i < dishes.length; i++) {
            if (dishes[i].getName().equals(dish)) {
                System.out.println("安装软件如下：");
                for(int j=0;j<dishes[i].soft;j++){
                    System.out.println(dishes[i].softwares[j].toString());
                }
            }
        }
    }


    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }


    public int getHardDiskcapacity() {
        return hardDiskcapacity;
    }

    public void setHardDiskcapacity(int hardDiskcapacity) {
        this.hardDiskcapacity = hardDiskcapacity;
    }

    public Dish[] getDishes() {
        return dishes;
    }

    public String getSize() {
        return size;
    }

    public void setSize(String size) {
        this.size = size;
    }

    public void setDishes(Dish[] dishes) {
        this.dishes = dishes;
    }
}
